package com.docmanage.web.controller.am;

import com.docmanage.am.domain.AmArchive;
import com.docmanage.am.service.impl.AmArchiveService;
import com.docmanage.common.annotation.Log;
import com.docmanage.common.core.controller.BaseController;
import com.docmanage.common.core.domain.AjaxResult;
import com.docmanage.common.core.page.TableDataInfo;
import com.docmanage.common.enums.BusinessType;
import com.docmanage.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 档案文件Controller
 * 
 * @author pointLion
 * @date 2023-06-18
 */
@RestController
@RequestMapping("/am/amArchive")
public class AmArchiveController extends BaseController
{
    @Autowired
    private AmArchiveService amArchiveService;

    /**
     * 查询档案文件列表
     */
    @PreAuthorize("@ss.hasPermi('am:amArchive:list')")
    @GetMapping("/list")
    public TableDataInfo list(AmArchive amArchive)
    {
        startPage();
        List<AmArchive> list = amArchiveService.selectAmArchiveList(amArchive);
        return getDataTable(list);
    }

    /**
     * 导出档案文件列表
     */
    @PreAuthorize("@ss.hasPermi('am:amArchive:export')")
    @Log(title = "档案文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AmArchive amArchive)
    {
        List<AmArchive> list = amArchiveService.selectAmArchiveList(amArchive);
        ExcelUtil<AmArchive> util = new ExcelUtil<AmArchive>(AmArchive.class);
        util.exportExcel(response, list, "档案文件数据");
    }

    /**
     * 获取档案文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('am:amArchive:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(amArchiveService.selectAmArchiveById(id));
    }

    /**
     * 新增档案文件
     */
    @PreAuthorize("@ss.hasPermi('am:amArchive:add')")
    @Log(title = "档案文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AmArchive amArchive)
    {
        return toAjax(amArchiveService.insertAmArchive(amArchive));
    }

    /**
     * 修改档案文件
     */
    @PreAuthorize("@ss.hasPermi('am:amArchive:edit')")
    @Log(title = "档案文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AmArchive amArchive)
    {
        return toAjax(amArchiveService.updateAmArchive(amArchive));
    }

    /**
     * 删除档案文件
     */
    @PreAuthorize("@ss.hasPermi('am:amArchive:remove')")
    @Log(title = "档案文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(amArchiveService.deleteAmArchiveByIds(ids));
    }




    /****
     * 查询文件夹下的所有文件
     * @param id
     * @return
     */
    @GetMapping(value = "/queryFileByFolderId/{id}")
    public AjaxResult queryFileByFolderId(@PathVariable("id")Long id){
        Map data = amArchiveService.queryFileByFolderId(id);
        return success(data);
    }
}
